// JavaScript Document
$(function () {
	$("#aMain").addClass("clickOn")
	$("#menu a").on("click",function(){
		$(this).siblings("a").removeClass("clickOn")
		 
		 $(this).addClass("clickOn")
	})
	$("#zhen").addClass("clickOn2")
	$("#ji").addClass("clickOff")


		$("#aMain").on("click",function(){
			$(".container").hide();
			$("#main").show();
		});
		$("#aFilm").on("click",function(){
			$(".container").hide();
			$("#film").show();

		});
		$("#aCinema").on("click",function(){
			$(".container").hide();
			$("#cinema").show();

		});
		$(".checkMore").on("click",function () {
			$(".container").hide();
			$("#film").show();
			$("#aFilm").trigger("click");
		})
	$(".checkCinema").on("click",function () {
		$(".container").hide();
		$("#cinema").show();
		$("#aCinema").trigger("click");
	})
		$(".filmRankingItemSmall").hover(function(){
			$(".filmRankingItemBig").hide();
			$(".filmRankingItemSmall").show()
			$(this).siblings(".filmRankingItemBig").show();
			$(this).hide();
		})
//		$(".filmRankingItemBig").mouseleave(function(){
//			$(".filmRankingItemBig").hide();
//			$(".filmRankingItemSmall").show();
//		})
	
		$("#zhen1").addClass("clickOn2")
	$("#ji1").addClass("clickOff")



	$("body").on("mouseenter", ".cinemaItem", function() {
		$(this).children(".cinemaItemScore").children(".cinemaItemcheak").show()
	});
	$("body").on("mouseleave", ".cinemaItem", function() {
		$(this).children(".cinemaItemScore").children(".cinemaItemcheak").hide()
	});
/*	$(".cinemaItem").hover(function(){
		$(this).children(".cinemaItemScore").children(".cinemaItemcheak").show()
	})*/
/*	$(".cinemaItem").mouseleave(function(){
			$(this).children(".cinemaItemScore").children(".cinemaItemcheak").hide()
	})*/
	$(document).on("click",".filmItem",function(){
		var title=$(this).find(".title").html();
		//alert(title)

		formpost("http://127.0.0.1:8080/show_film",{'Film_name' :title});
	})
	$(".filmRankingItemBigBtn").on("click",function (){
		var title=$(this).siblings(".filmRankingItemTitle").html();
		//alert(title)

		formpost("http://127.0.0.1:8080/show_film",{'Film_name' :title});
	})

	$(".filmRankingItemSmall").on("click",function(){
		window.location.replace("show_film")
	})
	function formpost(url, postData) {
		var tempform = document.createElement("form");
		tempform.action = url;
		tempform.target = "_blank";
		tempform.method = "post";
		tempform.style.display = "none";
		for (var x in postData) {
			var opt = document.createElement("textarea");
			opt.name = x;
			opt.value = postData[x];
			tempform.appendChild(opt);
		}
		document.body.appendChild(tempform);
		tempform.submit();
	}

	$(document).on("click",".cinemaItemcheak",function(){
		var title=$(this).parents(".cinemaItem").find("h4").html();
		//alert(title)
		formpost("http://127.0.0.1:8080/show_cinema",{'Cinema_name' :title});
	})
	$(".hotCinemaBtn").on("click",function(){
		var title=$(this).parents(".hotCinemaItem ").find(".hotCinemaText a").html();
		//alert(title)
		formpost("http://127.0.0.1:8080/show_cinema",{'Cinema_name' :title});
	})
	$("#cinemaRanking ol li").on("click",function(){
		var title=$(this).find("a").html();
		//alert(title)
		formpost("http://127.0.0.1:8080/show_cinema",{'Cinema_name' :title});
	})
	$("#cinemaMenuSearchSubmit").on("click",function () {
		var input= $("#cinemaMenuSearchInput").val()
		//alert(input)
		if(input==""){
			for(var i=0;i<$("#cinemaContent .cinemaItem").length;i++){
				var item=$("#cinemaContent .cinemaItem:eq("+i+")")
				//item.attr("hidden")
				item.removeAttr("hidden")
			}
		}else {

			for(var i=0;i<$("#cinemaContent .cinemaItem").length;i++){
				var item=$("#cinemaContent .cinemaItem:eq("+i+")")
				var title=item.children(".cinemaItemText").children("h4").text()
				//alert(title)
				var flag=0
				var titleArr=title.split("")
				var inputArr=input.split("")
				for(var x=0;x<inputArr.length;x++){
					for(var y=0;y<titleArr.length;y++){
						if(inputArr[x]==titleArr[y]){
							flag=1
						}
					}
				}
				if(flag==0){
					//alert(0)
					item.attr("hidden","true")
				}

			}
		}

	})
	$("#cinemaMenuSelect a").on("click",function (){
		var place= $(this).text();
		//alert(place)
		if(place=="全部区域"){
			//alert(1)
			$.ajax({
				type:"post",
				url:"http://127.0.0.1:8080/showAllCinemaByAsc",
				success:function(data){
					//alert("成功"+data.data.length);

					var str=""
					$("#cinemaContent").html(str)
					for(var i=0;i<data.data.length;i++){
						str="<div class=\"cinemaItem\" >\n" +
							"<div class=\"imgDiv\">\n" +
							"<img src='"+data.data[i].Img_Url+"'/>\n" +
							"</div>\n" +
							"<div class=\"cinemaItemText\">\n" +
							"<h4 >"+data.data[i].Cinema_name+"</h4><br>\n" +
							"<p >地址："+data.data[i].Cinema_address+"</p>\n" +
							"</div>\n" +
							"<div class=\"cinemaItemScore\">\n" +
							"<p>评分：<a class=\"ItemScore\" >"+data.data[i].Favorab_rate+"</a></p><br>\n" +
							"<div class=\"cinemaItemcheak\">选座</div>\n" +
							"</div>\n" +
							"</div>"
						$("#cinemaContent").append(str);
					}
				},

				error:function () {
					alert("错误");
				}
			});
		}else {
			$.ajax({
				type:"post",
				data:{place:place},
				url:"http://127.0.0.1:8080/showAllCinemaByPlace",
				success:function(data){
					if(data.data.length==0){
						alert("此地区暂未收录任何影院");
					}


					var str=""
					$("#cinemaContent").html(str)
					for(var i=0;i<data.data.length;i++){
						str="<div class=\"cinemaItem\" >\n" +
							"<div class=\"imgDiv\">\n" +
							"<img src='"+data.data[i].Img_Url+"'/>\n" +
							"</div>\n" +
							"<div class=\"cinemaItemText\">\n" +
							"<h4 >"+data.data[i].Cinema_name+"</h4><br>\n" +
							"<p >地址："+data.data[i].Cinema_address+"</p>\n" +
							"</div>\n" +
							"<div class=\"cinemaItemScore\">\n" +
							"<p>评分：<a class=\"ItemScore\" >"+data.data[i].Favorab_rate+"</a></p><br>\n" +
							"<div class=\"cinemaItemcheak\">选座</div>\n" +
							"</div>\n" +
							"</div>"
						$("#cinemaContent").append(str);
					}
				},

				error:function () {
					alert("错误");
				}
			});
		}
	})
	$("#cinemaOrderBtn").on("click",function(){
		$("#quan").trigger("click")
		if($(this).html()=="评分 ↑ "){
			$(this).html("评分 ↓ ")
			$.ajax({
				type:"post",
				url:"http://127.0.0.1:8080/showAllCinemaByAsc",
				success:function(data){
					//alert("成功"+data.data.length);

					var str=""
					$("#cinemaContent").html(str)
					for(var i=0;i<data.data.length;i++){
						str="<div class=\"cinemaItem\" >\n" +
							"<div class=\"imgDiv\">\n" +
							"<img src='"+data.data[i].Img_Url+"'/>\n" +
							"</div>\n" +
							"<div class=\"cinemaItemText\">\n" +
							"<h4 >"+data.data[i].Cinema_name+"</h4><br>\n" +
							"<p >地址："+data.data[i].Cinema_address+"</p>\n" +
							"</div>\n" +
							"<div class=\"cinemaItemScore\">\n" +
							"<p>评分：<a class=\"ItemScore\" >"+data.data[i].Favorab_rate+"</a></p><br>\n" +
							"<div class=\"cinemaItemcheak\">选座</div>\n" +
							"</div>\n" +
							"</div>"
						$("#cinemaContent").append(str);
					}
				},

				error:function () {
					alert("错误");
				}
			});
		}else{
			$(this).html("评分 ↑ ")
			$.ajax({
				type:"post",
				url:"http://127.0.0.1:8080/showAllCinemaByDesc",
				success:function(data){
					//alert("成功"+data.data.length);

					var str=""
					$("#cinemaContent").html(str)
					for(var i=0;i<data.data.length;i++){
						str="<div class=\"cinemaItem\" >\n" +
							"<div class=\"imgDiv\">\n" +
							"<img src='"+data.data[i].Img_Url+"'/>\n" +
							"</div>\n" +
							"<div class=\"cinemaItemText\">\n" +
							"<h4 >"+data.data[i].Cinema_name+"</h4><br>\n" +
							"<p >地址："+data.data[i].Cinema_address+"</p>\n" +
							"</div>\n" +
							"<div class=\"cinemaItemScore\">\n" +
							"<p>评分：<a class=\"ItemScore\" >"+data.data[i].Favorab_rate+"</a></p><br>\n" +
							"<div class=\"cinemaItemcheak\">选座</div>\n" +
							"</div>\n" +
							"</div>"
						$("#cinemaContent").append(str);
					}
				},

				error:function () {
					alert("错误");
				}
			});
		}

	})
	$("#cinemaMenuSelect a").on("click",function(){
		$(this).siblings("a").removeClass("cinemaSelected")
		$(this).addClass("cinemaSelected")

	})
	$("#onlineList_menu #zhen").on("click",function(){
		$(this).siblings("a").removeClass("clickOn2").addClass("clickOff")
		$(this).addClass("clickOn2").removeClass("clickOff")
		$.ajax({
			type:"post",
			url:"http://127.0.0.1:8080/FindonLineFilms",
			success:function(data){
				//alert("成功"+data.data.length);
				var str=""
				$("#onLineFilm").html(str)
				for(var i=0;i<data.data.length;i++){
					str="<div class=\"filmItem\"  >\n" +
						"<div class=\"imgA\">\n" +
						"<img src='"+data.data[i].Url+"'>\n" +
						"<div class=\"textArea\">\n" +
						"<b class=\"title filmItemText\" >"+data.data[i].Film_name+"</b><b class=\"score filmItemText\" >"+data.data[i].Score+"</b>\n" +
						"</div>\n" +
						"<div class=\"btnOrder\"><b class=\"filmItemText\">选座购票</b></div>\n" +
						"</div></div>"
					$("#onLineFilm").append(str);
				}
			},

			error:function () {
				alert("错误");
			}
		});
	})
	$("#onlineList_menu #ji").on("click",function(){
		$(this).siblings("a").removeClass("clickOn2").addClass("clickOff")
		$(this).addClass("clickOn2").removeClass("clickOff")
		$.ajax({
			type:"post",
			url:"http://127.0.0.1:8080/FindForthcomingFilms",
			success:function(data){
				//alert("成功"+data.data.length);
				var str=""
				$("#onLineFilm").html(str)
				for(var i=0;i<data.data.length;i++){
					str="<div class=\"filmItem\"  >\n" +
						"<div class=\"imgA\">\n" +
						"<img src='"+data.data[i].Url+"'>\n" +
						"<div class=\"textArea\">\n" +
						"<b class=\"title filmItemText\" >"+data.data[i].Film_name+"</b><b class=\"score filmItemText\" >"+data.data[i].Score+"</b>\n" +
						"</div>\n" +
						"<div class=\"btnOrder\"><b class=\"filmItemText\">选座购票</b></div>\n" +
						"</div></div>"
					$("#onLineFilm").append(str);
				}
			},

			error:function () {
				alert("错误");
			}
		});
	})
	$("#filmList_menu #zhen1").on("click",function(){
		//alert(1)
		$(this).siblings("a").removeClass("clickOn2").addClass("clickOff")
		$(this).addClass("clickOn2").removeClass("clickOff")
		$.ajax({
			type:"post",
			url:"http://127.0.0.1:8080/findAllOnlineFilms",
			success:function(data){
				//alert("成功"+data.data.length);
				var str=""
				$("#Films").html(str)
				for(var i=0;i<data.data.length;i++){
					str="<div class=\"filmItem\" th:each=\"a_film, itemStat: ${AllOnlineFilm}\">\n" +
						"<div class=\"imgA\">\n" +
						"<img src='"+data.data[i].Url+"'>\n" +
						"<div class=\"textArea1\">\n" +
						"<b class=\"title filmItemText\" >"+data.data[i].Film_name+"</b><b class=\"score filmItemText\" >"+data.data[i].Score+"</b>\n" +
						"</div>\n" +
						"<div class=\"btnOrder1\"><b class=\"filmItemText\">选座购票</b></div>\n" +
						"</div>\n" +
						"</div>"
					$("#Films").append(str);
				}
			},

			error:function () {
				alert("错误");
			}
		});
	})
	$("#filmList_menu #ji1").on("click",function(){
		//alert(1)
		$(this).siblings("a").removeClass("clickOn2").addClass("clickOff")
		$(this).addClass("clickOn2").removeClass("clickOff")
		$.ajax({
			type:"post",
			url:"http://127.0.0.1:8080/findAllForthcomingFilms",
			success:function(data){
				//alert("成功"+data.data.length);
				var str=""
				$("#Films").html(str)
				for(var i=0;i<data.data.length;i++){
					str="<div class=\"filmItem\" th:each=\"a_film, itemStat: ${AllOnlineFilm}\">\n" +
						"<div class=\"imgA\">\n" +
						"<img src='"+data.data[i].Url+"'>\n" +
						"<div class=\"textArea1\">\n" +
						"<b class=\"title filmItemText\" >"+data.data[i].Film_name+"</b><b class=\"score filmItemText\" >"+data.data[i].Score+"</b>\n" +
						"</div>\n" +
						"<div class=\"btnOrder1\"><b class=\"filmItemText\">选座购票</b></div>\n" +
						"</div>\n" +
						"</div>"
					$("#Films").append(str);
				}
			},

			error:function () {
				alert("错误");
			}
		});
	})
})